import type { Column } from "@/components/CrudPage/type";

import {
  deleteKnoDocGroup,
  type KnoDocGroup
} from "@/views/domain/knowledge/api/knoDocGroup";
import { messager } from "@/utils/message";
import { ref } from "vue";

export function useKnoDocGroupProvider() {
  // 列配置
  const columns: Column[] = [
    {
      label: "",
      prop: "id",
      slot: "id",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "title",
      slot: "title",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "desc",
      slot: "desc",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "操作",
      prop: "operation",
      slot: "operation"
    }
  ];

  // 删除row
  const deleteRow = (row: KnoDocGroup) => {
    deleteKnoDocGroup(row).then(({ ok, msg }) => {
      messager.alert(ok, msg);
    });
  };

  return {
    columns,
    deleteRow
  };
}

class KDGProvider {
  loadSymble = ref<boolean>(false);
}

export const provider = new KDGProvider();
